package homePage;

import jugador.Jugador;
import jugador.Persona;

import org.apache.wicket.Page;
import org.apache.wicket.pageStore.PageWindowManager;
import org.apache.wicket.pageStore.PageWindowManager.PageWindow;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.pages.RedirectPage;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.settings.IPageSettings;

import ruletaPage.TableroPage;

import applications.RuletaApplication;

import Ruleta.Mesa;

public class HomePage extends WebPage {
	private static final long serialVersionUID = 1L;

	private String nombreActual;
	private Integer fichas;

	public HomePage() {

		formularioUnirse();

	}

	public void formularioUnirse() {

		@SuppressWarnings("serial")
		Form<String> unirseForm = new Form<String>("unirseForm") {

			public void onSubmit() {
				if (RuletaApplication.getInstance().getMesa().hayLugarDisponible() && !(RuletaApplication.getInstance().isEstaRepetido(nombreActual))) {
					Jugador j = RuletaApplication.getInstance().creaJugador(nombreActual, fichas);
					setResponsePage(new TableroPage(j));
				} else {
					if (!(RuletaApplication.getInstance()
								.isEstaRepetido(nombreActual))){
						setResponsePage(ApodoUtilizadoPage.class);
					}else{
						setResponsePage(ErrorPage.class);
					}
				}
			}
					
		};

		add(unirseForm);
		unirseForm.add(new TextField<String>("nombre",new PropertyModel<String>(this, "nombreActual")));
		unirseForm.add(new TextField<String>("fichas",new PropertyModel<String>(this, "fichas")));
		unirseForm.add(new Label("labelNombre", "Apodo: "));
		unirseForm.add(new Label("labelFichas", "Cantidad de dinero: "));
	}

}